﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Regnemaskinen.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Regnemaskinen</title>
    <script type="text/javascript">
        window.onload = function () {

            var submit_btn = document.getElementById('uiSubmit');

            submit_btn.onclick = function () {

                if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp = new XMLHttpRequest();
                }
                else {// code for IE6, IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.open("POST", "Calc.aspx", false);

                xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                var lhs = encodeURIComponent(document.getElementById('uiFirstinput').value);
                var op = encodeURIComponent(document.getElementById('uiOperator').value);
                var rhs = encodeURIComponent(document.getElementById('uiSecondinput').value);

                var params = 'lhs=' + lhs + '&op=' + op + '&rhs=' + rhs;
                console.log(params);

                xmlhttp.send(params);
                //xmlDoc = xmlhttp.responseXML;

                htmlText = xmlhttp.responseText;

                var o = document.createElement('div');
                o.innerHTML = htmlText;
                document.getElementById('wrapper').appendChild(o);

            };
        };
    </script>
</head>
<body>
    <div id="wrapper">
        <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="uiFirstinput" runat="server"></asp:TextBox>
                <asp:DropDownList ID="uiOperator" runat="server">
                    <asp:ListItem Text="/" Value="/"></asp:ListItem>
                    <asp:ListItem Text="*" Value="*"></asp:ListItem>
                    <asp:ListItem Text="-" Value="-"></asp:ListItem>
                    <asp:ListItem Text="+" Value="+"></asp:ListItem>
                </asp:DropDownList>
                <asp:TextBox ID="uiSecondinput" runat="server"></asp:TextBox>

                <input type="button" id="uiSubmit" value="Submit" />
            </div>
        </form>
    </div>
</body>
</html>
